//
//  ReleaseDeliciousFoodThereController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/24.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "ReleaseDeliciousFoodThereController.h"
#import "ReleaseDeliciousFoodModel.h"

@interface ReleaseDeliciousFoodThereController ()
/**输入框*/
@property (nonatomic,strong)PubulicTextView*textView;
@end

@implementation ReleaseDeliciousFoodThereController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavItems];
    
    [self.view addSubview:self.textView];
    
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.right.bottom.mas_equalTo(-16);
    }];
}
-(void)releseAction{

    ReleaseFoodManage.introduce = self.textView.textView.text;
    NSMutableArray * seasoningArray = [NSMutableArray array];
    
    for (NSMutableArray * array in ReleaseFoodManage.seasoningArray) {
        
        NSMutableArray * subArray = [NSMutableArray array];
        for (ReleaseDeliciousFoodModel * model in array) {
            
            
            NSMutableDictionary * modelDic = [NSMutableDictionary dictionary];
            if (StrValid(model.leftName)) {
                [modelDic setValue:model.leftName forKey:@"leftName"];
            }
            if (StrValid(model.rightName)) {
                [modelDic setValue:model.rightName forKey:@"rightName"];
            }
            [subArray addObject:modelDic];
            
        }
        [seasoningArray addObject:subArray];
    }
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:@"购物狂" forKey:@"name"];
    [dic setValue:@"user2" forKey:@"userIcon"];
    [dic setValue:ReleaseFoodManage.title forKey:@"title"];
    [dic setValue:ReleaseFoodManage.images forKey:@"images"];
    [dic setValue:ReleaseFoodManage.styleOfCooking forKey:@"styleOfCooking"];
    [dic setValue:ReleaseFoodManage.introduce forKey:@"introduce"];
    [dic setValue:seasoningArray forKey:@"seasoningArray"];

    [PlistTool savePlistValue:dic Type:ReleseFood];
    [self postNotification];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void)postNotification{
    [[NSNotificationCenter defaultCenter] postNotificationName:K_ReleaseDeliciousFood object:nil];
}
-(void)setNavItems{
    self.title = @"发布（3/3）";
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setBackgroundImage:IMAGE_NAMED(@"back") forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [leftBtn setTitleColor:UIColorFromRGB(0x273323) forState:UIControlStateNormal];
    leftBtn.titleLabel.font = SYSTEMFONT(16);
    [leftBtn sizeToFit];
    
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"发布" forState:UIControlStateNormal];
    [rightBtn setTitleColor:UIColorFromRGB(0x959E97) forState:UIControlStateNormal];
    rightBtn.titleLabel.font = SYSTEMFONT(16);
    [rightBtn sizeToFit];
    
    kWeakSelf(weakSelf);
    [rightBtn addActionHandler:^{
        
        if (self.textView.textView.text.length == 0) {
            ShowHubMessage(@"请添加作品介绍");
            return ;
        }
        
        [weakSelf releseAction];
    }];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];

    
}

-(PubulicTextView*)textView{
    if(!_textView){
        _textView=[PubulicTextView new];
        _textView.placeholderText.text = @"介绍一下你的作品吧（如：作品特色，卖点，创意，制作要点，研发）";
    }
    return _textView;
}
@end
